﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.IO;
using System.Configuration;
using System.Web.Configuration;

namespace DnDFileUpload
{
    public partial class Default : System.Web.UI.Page
    {
        /// <summary>
        /// The max file size in bytes
        /// </summary>
        protected int maxRequestLength
        {
            get
            {
                HttpRuntimeSection section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;

                if (section != null)
                    return section.MaxRequestLength * 1024; // Default Value
                else
                    return 4096 * 1024; // Default Value
            }
        }

        /// <summary>
        /// Page Load
        /// </summary>
        /// 
        protected string fileName = "xin chao";
        protected void Page_Load(object sender, EventArgs e)
        {
           
            handleFileUpload();
           
          
        }

        /// <summary>
        /// Checks if a file is sent to the server
        /// and saves it to the Uploads folder.
        /// </summary>
        private void handleFileUpload()
        {
            if (!string.IsNullOrEmpty(Request.Headers["X-File-Name"]))
            {
                string path = Server.MapPath(string.Format("~/Uploads/{0}", Request.Headers["X-File-Name"]));
                Stream inputStream = Request.InputStream;

                FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate);

                inputStream.CopyTo(fileStream);
                Response.Write(fileName);
                Context.Response.ContentType="text/html";
                Context.Response.Write("thanh cong"+path);
                fileStream.Close();
               
            }
        }
    }
}